
with open('data/problem042.txt') as file:
    list = [w.strip('\"') for w in file.read().split(',')]


limit = len(sorted(list, key=lambda x:len(x))[-1])\
             * (ord('Z') + 1 - ord('A'))

triangles = set()
n = 1
while True:
    tri = n * (1 + n) / 2
    if tri > limit:
        break
    triangles.add(tri)
    n += 1

count = 0
for word in list:
    if sum([ord(letter) + 1 - ord('A') \
        for letter in word]) in triangles:
        count += 1
print count

